﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace MoneyManagerNET.Infrastructure
{
    public class OverwriteFileTraceListener : TextWriterTraceListener
    {

        public OverwriteFileTraceListener(string fileName)
            : base(File.Open(fileName, FileMode.OpenOrCreate))
        {

            this.WriteLine(string.Format(">>>{0}", DateTime.Now));
            this.WriteLine(string.Format(">>>file:{0}", fileName));

        }
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, params object[] data)
        {
            base.TraceData(eventCache, source, eventType, id, data);
        }

        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            //if (data is Exception) { var exp = data as Exception; TraceEvent(eventCache, source, eventType, id, "Message: {1}", exp.Message); TraceEvent(eventCache, source, eventType, id, "StackTrace: {1}", exp.StackTrace); }
            //else 
                base.TraceData(eventCache, source, eventType, id, data);
        }
    }
}
